**Figure 1 in word document
**Figure 2 lines 36-98
**Table 1  lines 108-122
**Table 2  lines 124-128
**Table 3  line 133
**Figure 3 lines 136-162
**Figure 4 lines 166-190
**Figure 5 lines 193-199
**Table 4  lines 203-216
**APPENDIX
**Figure A.1 lines 225-232
**Table A.1  lines 235-243
**Figure A.2 lines 101-106
**Figure A.3 lines 247-257
**Figure A.4 lines 262-274
**Figure A.5 lines 279-291
**Figure A.6 lines 294-306


*******************************************************
*Step 1: Define library and open file
*******************************************************
*install these if not already
capture ssc install tabplot
capture ssc install catplot
*install grc1leg2 
capture findit grc1leg2
*set your library directory
global   newdir2=`"D:\Dropbox\CDF 2\2020 CDF paper\BJPS submission\Political Behaviour\first round\public files"'

******************
***Figure 1: Sample figure, in article
********************

*******************
***Figure 2*********
********************
use "$newdir2\mpsexpenditure.dta", clear

graph bar edu  health water roads electrification admin oth, stack scale(*.8) legend(region(col(white))) plotregion(fcolor(white)) graphregion(fcolor(white))  legend(size(small) label(1 "Education") label(2 "Health") label(3 "Water") label(4 "Roads & Bridges") label(5 "Electrification") label(6 "Admin") label(7 "Other")) ytitle("How the MP spent the CDF over 2008-2013")  blabel(bar , position(inside) format(%9.1f)) saving(three, replace)



use "$newdir2\newcdf2.dta", clear
sort constituencynow
merge constituencynow using "$newdir2\mpsexpenditure.dta"
drop _merge


gen pdiscedu=edu-prefedu
label var pdiscedu "Difference in CDF expenditure and preference on education"

gen pdiscadmin=admin-prefadmincdf
label var pdiscadmin "Difference in CDF expenditure and preference on administration"

gen pdischealth=health-prefhealth
label var pdischealth "Difference in CDF expenditure and preference on health"

gen pdiscwater=water-prefwater
label var pdiscwater "Difference in CDF expenditure and preference on water"

gen pdiscroads=roads-prefroadbridge
label var pdiscroads "Difference in CDF expenditure and preference on roads"

gen pdiscelec=electrification-prefelectri
label var pdiscelec "Difference in CDF expenditure and preference on electricity"

gen pdiscother=other-prefoth
label var pdiscother "Difference in CDF expenditure and preference on other"


gen prefdifedu=prefedu-thinkedu
label var prefdifedu "Difference in preference about CDF expenditure and belief about how CDF was spent on education"

gen prefdifadmin=prefadmincdf-thinkadmincdf
label var prefdifadmin "Difference in preference about CDF expenditure and belief about how CDF was spent on admin"
 
gen prefdifhealth=prefhealth-thinkhealth
label var prefdifhealth "Difference in preference about CDF expenditure and belief about how CDF was spent on health"

gen prefdifwater=prefwater-thinkwater
label var prefdifwater "Difference in preference about CDF expenditure and belief about how CDF was spent on water"

gen prefdifroads=prefroadbridge-thinkroadbridge
label var prefdifroads "Difference in preference about CDF expenditure and belief about how CDF was spent on roads"

gen prefdifelec=prefelectri-thinkelectri
label var prefdifelec "Difference in preference about CDF expenditure and belief about how CDF was spent on electricity"


gen prefdifother=prefoth-thinkoth 
label var prefdifother "Difference in preference about CDF expenditure and belief about how CDF was spent on other"


graph bar prefedu  prefhealth prefwater prefroadbridge prefelectri prefadmincdf prefoth, stack scale(*.8) legend(region(col(white))) plotregion(fcolor(white)) graphregion(fcolor(white))  legend(size(small) label(1 "Education") label(2 "Health") label(3 "Water") label(4 "Roads & Bridges") label(5 "Electrification") label(6 "Admin") label(7 "Other")) ytitle("Preference about how the CDF should have been spent")  blabel(bar , position(inside) format(%9.1f)) saving(one, replace)
graph bar thinkedu  thinkhealth thinkwater thinkroadbridge thinkelectri thinkadmincdf thinkoth thinkmpcorrupt, stack scale(*.8) legend(region(col(white))) plotregion(fcolor(white)) graphregion(fcolor(white))  legend(size(small) label(1 "Education") label(2 "Health") label(3 "Water") label(4 "Roads & Bridges") label(5 "Electrification") label(6 "Admin") label(7 "Other") label(8 "Misused in corruption")) ytitle("Perception about how the CDF was actually spent")  blabel(bar , position(inside) format(%9.1f)) saving(two, replace)
graph combine one.gph two.gph  three.gph, rows(1) graphregion(color(white)) 
graph save Graph "$newdir2\fig2.gph", replace

*******************
***Figure A.2*********
********************
graph bar prefedu  prefhealth prefwater prefroadbridge prefelectri prefadmincdf prefoth, stack over(ethnicity) scale(*.8) plotregion(fcolor(white)) graphregion(fcolor(white)) legend(label(1 "Education") label(2 "Health") label(3 "Water") label(4 "Roads & Bridges") label(5 "Electrification") label(6 "Admin") label(7 "Other")) ytitle("Preference about how the CDF should have been spent")  saving(four, replace)
graph bar thinkedu  thinkhealth thinkwater thinkroadbridge thinkelectri thinkadmincdf thinkoth thinkmpcorrupt, stack over(ethnicity) scale(*.8) plotregion(fcolor(white)) graphregion(fcolor(white))  plotregion(fcolor(white)) graphregion(fcolor(white)) legend(label(1 "Education") label(2 "Health") label(3 "Water") label(4 "Roads & Bridges") label(5 "Electrification") label(6 "Admin") label(7 "Other") label(8 "Misused in corruption")) ytitle("Perception about how the CDF was actually spent") saving(five, replace)
graph combine four.gph five.gph,  graphregion(color(white)) 
graph save Graph "$newdir2\figA2.gph", replace

****************
***Table 1
*****************
capture erase "$newdir2\table1.xml"
capture erase "$newdir2\table1.txt"

capture erase "$newdir2\table2.xml"
capture erase "$newdir2\table2.txt"

global controls  copartisan fullcoethnic i.reelected wfood female rural age numchildren employed edu assetind  
foreach var of varlist  prefdifedu  prefdifhealth prefdifwater prefdifroads prefdifelec  prefdifadmin prefdifother {

reg `var' $controls, vce(cl constituencynow)
estimates store `var'
outreg2 using "$newdir2\table1.xml", se bdec(3) e(r2_a) excel append
}

foreach var of varlist  pdiscedu  pdischealth pdiscwater pdiscroads pdiscelec pdiscadmin pdiscother{
reg `var' $controls, vce(cl constituencynow)
estimates store `var'
outreg2 using "$newdir2\table2.xml", se bdec(3) e(r2_a) excel append
}

****
*Table 3
***
tab treatment

*******************
***Figure 3*********
********************
reg disagreespend i.treatment i.reelected##i.treatment pdiscedu pdischealth pdiscwater pdiscroads pdiscelec pdiscadmin pdiscother thinkmpcorr  , vce(cl constituencynow)
estimates store exper


*difference in thinking and reality
coefplot exper, xline(0, lcolor(red) lwidth(thin) lpattern(dash)) omitted baselevels drop(_cons 0.reelected#0.treatment 0.reelected#1.treatment 0.reelected#2.treatment 0.reelected#3.treatment 0.reelected#4.treatment)  levels(95)   xsize(7) ysize(4) ///
     headings(0.treatment = "{bf:Treatment}"                        ///
	          0.reelected = "{bf:MP election status in 2013}"       ///
              1.reelected#0.treatment = "{bf:Interaction Effect}"   ///
			  pdiscedu = "{bf:CDF spending minus preferred spending in:}") saving(first, replace)     
graph save Graph "$newdir2\fig3panela.gph", replace

**with controls
global controls    blockluo wfood female rural age numchildren employed edu assetind  
reg disagreespend i.treatment i.reelected##i.treatment pdiscedu  pdischealth pdiscwater pdiscroads pdiscelec pdiscadmin pdiscother thinkmpcorr  $controls, vce(cl constituencynow)
estimates store exper

*difference in thinking and reality
coefplot exper, scale(*.8 )xline(0, lcolor(red) lwidth(thin) lpattern(dash)) omitted baselevels drop(_cons 0.reelected#0.treatment 0.reelected#1.treatment 0.reelected#2.treatment 0.reelected#3.treatment 0.reelected#4.treatment)  levels(95)   xsize(10) ysize(7) ///
     headings(0.treatment = "{bf:Treatment}"                        ///
	          0.reelected = "{bf:MP election status in 2013}"       ///
              1.reelected#0.treatment = "{bf:Interaction Effect}"   ///
			  pdiscedu = "{bf:CDF spending minus preferred spending in:}"   /// 
			   blockluo = "{bf:Controls:}")  saving(firstc, replace)  
graph save Graph "$newdir2\fig3panelb.gph", replace


*******
*Figure 4
********
reg voteagain   i.treatment i.reelected##i.treatment pdiscedu pdischealth pdiscwater pdiscroads pdiscelec pdiscadmin pdiscother thinkmpcorrupt, vce(cl constituencynow)
estimates store again1

coefplot again1, xline(0, lcolor(red) lwidth(thin) lpattern(dash)) omitted baselevels drop(_cons 0.reelected#0.treatment 0.reelected#1.treatment 0.reelected#2.treatment 0.reelected#3.treatment 0.reelected#4.treatment)  levels(95)   xsize(8) ysize(4) ///
     headings(0.treatment = "{bf:Treatment}"                        ///
	          0.reelected = "{bf:MP election status in 2013}"       ///
              1.reelected#0.treatment = "{bf:Interaction Effect}"   ///
			  pdiscedu = "{bf:CDF spending minus preferred spending in:}") saving(secondt, replace) 
graph save Graph  "$newdir2\fig4panela.gph", replace


***CONTROLS
global controls    blockluo wfood female rural age numchildren employed edu assetind  
reg voteagain   i.treatment i.reelected##i.treatment pdiscedu pdischealth pdiscwater pdiscroads pdiscelec pdiscadmin pdiscother thinkmpcorrupt $controls , vce(cl constituencynow)
estimates store again1

coefplot again1, scale(*.8) xline(0, lcolor(red) lwidth(thin) lpattern(dash)) omitted baselevels drop(_cons 0.reelected#0.treatment 0.reelected#1.treatment 0.reelected#2.treatment 0.reelected#3.treatment 0.reelected#4.treatment)  levels(95)   xsize(10) ysize(7) ///
     headings(0.treatment = "{bf:Treatment}"                        ///
	          0.reelected = "{bf:MP election status in 2013}"       ///
              1.reelected#0.treatment = "{bf:Interaction Effect}"   ///
			  pdiscedu = "{bf:CDF spending minus preferred spending in:}"   ///
			  blockluo = "{bf:Controls:}")  saving(secondtc, replace)  
graph save Graph "$newdir2\fig4panelb.gph", replace

*****
**Figure 5
reg  auditwaste ib2.treatment if auditwaste>0 & auditwaste~=., vce(cl constituencynow)
estimates store balance

coefplot balance, scale(*.95) xtitle (percentage of misuse found in audit)xline(0, lcolor(red) lwidth(thin) lpattern(dash)) omitted baselevels drop(_cons) levels(95)   xsize(8) ysize(4) ///
     headings(0.treatment = "{bf:Treatment}")  saving(auditdif, replace) 
graph save Graph "$newdir2\fig5.gph", replace


*****
***Table 4
****
capture erase "$newdir2\table4.xml"
capture erase "$newdir2\table4.txt"

reg voteagainaudit  ib2.treatment   auditwaste ib2.treatment#c.auditwaste i.reelected pdiscedu  pdischealth pdiscwater pdiscroads pdiscelec pdiscadmin pdiscother thinkmpcorrupt if auditwaste>=0 & auditwaste~=., vce(cl constituencynow)
outreg2 using "$newdir2\table4.xml", se bdec(3) e(r2_a) excel append


reg voteagainaudit  ib2.treatment   auditwaste ib2.treatment#c.auditwaste i.reelected##ib2.treatment pdiscedu  pdischealth pdiscwater pdiscroads pdiscelec pdiscadmin pdiscother thinkmpcorrupt if auditwaste>=0 & auditwaste~=., vce(cl constituencynow)
outreg2 using "$newdir2\table4.xml", se bdec(3) e(r2_a) excel append

reg voteagainaudit   ib2.treatment   auditwaste ib2.treatment#c.auditwaste i.reelected##ib2.treatment pdiscedu pdischealth pdiscwater pdiscroads pdiscelec pdiscadmin  pdiscother thinkmpcorrupt $controls if auditwaste>=0 & auditwaste~=., vce(cl constituencynow)
outreg2 using "$newdir2\table4.xml", se bdec(3) e(r2_a) excel append





**APPENDIX

*************** 
**Figure A.1
*************
use "$newdir2\newcdf2.dta", clear

graph hbar, ///
over(mpimport, label(labsize(small)))    ///
over(rural,label(labsize(small)))  ///
ytitle("Percent of Respondents") graphregion(color(white))
graph save Graph "$newdir2\figA1.gph", replace  

****
**Table A.1
************
sum female age1826 edu assetind wfood employed haschildren numchildren rural 
tab ethnicity 
tab province 

sum female age1826 edu assetind wfood employed haschildren numchildren rural if treatment~=.
tab ethnicity if treatment~=.
tab province if treatment~=.


*******************
***Figure A.3*********
********************
global controls  blockluo blockkikuyo wfood female rural age numchildren employed edu assetind  
foreach var of varlist  prefedu prefadmin  prefhealth prefwater prefroadbridge prefelectri prefoth {

reg `var' $controls, vce(cl constituencynow)
estimates store `var'
}

coefplot (prefedu, label (Education)  msymbol(X)) (prefhealth, label (Health)  msymbol(D)) (prefwater, label (Water)  msymbol(S)) (prefroadbridge, label (Roads) msymbol(Oh)) (prefelectri, label (Electrification) msymbol(T)) (prefadmincdf, label (Admin) msymbol(A)), drop(_cons) levels(95) xline(0, lcolor(red) lwidth(thin) lpattern(dash)) xsize(5) ysize(3.8)
graph save Graph "$newdir2\figA3.gph", replace



*******************
***Figure A.4*********
********************
foreach var of varlist   blockluo wfood female rural age numchildren employed edu assetind {
reg `var' i.treatment i.reelected##i.treatment, vce(cl constituencynow)
estimates store `var'
}
coefplot (blockluo, label (Ethnic group supported Odinga)  msymbol(X)) (wfood, label (Without food to eat)  msymbol(D)) (female, label (Female)  msymbol(S)) (rural, label (Rural) msymbol(Oh)) (age, label (Age) msymbol(T)) ///
(numchildren, label (Number of children) msymbol(A)) (employed, label (Employed)  msymbol(oh)) (edu, label (Secondary or greater education)  msymbol(x)) (assetind, label (Asset index)  msymbol(s)),  xline(0, lcolor(red) lwidth(thin) lpattern(dash)) ///
omitted baselevels drop(_cons 1.reelected#0.treatment 0.reelected#1.treatment 0.reelected#2.treatment 0.reelected#3.treatment 0.reelected#4.treatment) levels(95)   scale(*.8) xsize(8) ysize(5) ///
     headings(0.treatment = "{bf:Treatment}"    ///
	                   0.reelected = "{bf:MP election status in 2013}"       ///
                       0.reelected#0.treatment = "{bf:Interaction Effect}") saving(balancetret, replace) 
graph save Graph "$newdir2\figA4.gph", replace



*******************
***Figure A.5*********
********************
foreach var of varlist edu  health water roads electrification admin other {
reg `var' i.treatment i.reelected##i.treatment, vce(cl constituencynow)
estimates store `var'
}
coefplot (edu, label (Education)  msymbol(X)) (health, label (Health)  msymbol(D)) (water, label (Water)  msymbol(S)) (roads, label (Roads) msymbol(Oh)) (electrification, label (Electrification) msymbol(T)) ///
(admin, label (Admin) msymbol(A)) (other, label (Other)  msymbol(oh)),  xline(0, lcolor(red) lwidth(thin) lpattern(dash)) ///
omitted baselevels drop(_cons 1.reelected#0.treatment 0.reelected#1.treatment 0.reelected#2.treatment 0.reelected#3.treatment 0.reelected#4.treatment) levels(95)   scale(*.8) xsize(8) ysize(5) ///
     headings(0.treatment = "{bf:Treatment}"    ///
	                   0.reelected = "{bf:MP election status in 2013}"       ///
                       0.reelected#0.treatment = "{bf:Interaction Effect}") saving(balancetret, replace) 
graph save Graph "$newdir2\figA5.gph", replace

************
*Figure A.6
*************

catplot oneqtt, asyvars stack percent percent vertical blabel(bar, pos(base) size(3) format(%9.1f))  plotregion(fcolor(white)) graphregion(fcolor(white)) bar(1, color(maroon) fintensity(inten80)) bar(2, color(maroon) fintensity(inten60)) bar(3, color(gray) fintensity(inten80)) bar(4, color(navy) fintensity(inten60)) bar(5, color(navy) fintensity(inten80)) bar(6, color(black) fintensity(inten60)) bar(7, color(brown) fintensity(inten60)) saving(onett, replace)
catplot twoqtt, asyvars stack percent percent vertical blabel(bar, pos(base) size(3) format(%9.1f))  plotregion(fcolor(white)) graphregion(fcolor(white)) bar(1, color(maroon) fintensity(inten80)) bar(2, color(maroon) fintensity(inten60)) bar(3, color(gray) fintensity(inten80)) bar(4, color(navy) fintensity(inten60)) bar(5, color(navy) fintensity(inten80)) bar(6, color(black) fintensity(inten60)) bar(7, color(brown) fintensity(inten60)) saving(twott, replace)
catplot threeqtt, asyvars stack percent percent vertical blabel(bar, pos(base) size(3) format(%9.1f))  plotregion(fcolor(white)) graphregion(fcolor(white)) bar(1, color(maroon) fintensity(inten80)) bar(2, color(maroon) fintensity(inten60)) bar(3, color(gray) fintensity(inten80)) bar(4, color(navy) fintensity(inten60)) bar(5, color(navy) fintensity(inten80)) bar(6, color(black) fintensity(inten60)) bar(7, color(brown) fintensity(inten60))  saving(threett, replace)
catplot fourqtt, asyvars stack percent percent vertical blabel(bar, pos(base) size(3) format(%9.1f))  plotregion(fcolor(white)) graphregion(fcolor(white)) bar(1, color(maroon) fintensity(inten80)) bar(2, color(maroon) fintensity(inten60)) bar(3, color(gray) fintensity(inten80)) bar(4, color(navy) fintensity(inten60)) bar(5, color(navy) fintensity(inten80)) bar(6, color(black) fintensity(inten60)) bar(7, color(brown) fintensity(inten60))  saving(fourtt, replace)
catplot fiveqtt, asyvars stack percent percent vertical blabel(bar, pos(base) size(3) format(%9.1f))  plotregion(fcolor(white)) graphregion(fcolor(white)) bar(1, color(maroon) fintensity(inten80)) bar(2, color(maroon) fintensity(inten60)) bar(3, color(gray) fintensity(inten80)) bar(4, color(navy) fintensity(inten60)) bar(5, color(navy) fintensity(inten80)) bar(6, color(black) fintensity(inten60)) bar(7, color(brown) fintensity(inten60))   saving(fivett, replace)
catplot sixqtt, asyvars stack percent percent vertical blabel(bar, pos(base) size(3) format(%9.1f))  plotregion(fcolor(white)) graphregion(fcolor(white)) bar(1, color(maroon) fintensity(inten80)) bar(2, color(maroon) fintensity(inten60)) bar(3, color(gray) fintensity(inten80)) bar(4, color(navy) fintensity(inten60)) bar(5, color(navy) fintensity(inten80)) bar(6, color(black) fintensity(inten60)) bar(7, color(brown) fintensity(inten60))  saving(sixtt, replace)
grc1leg2 onett.gph twott.gph threett.gph fourtt.gph fivett.gph sixtt.gph, legendfrom(onett.gph) graphregion(color(white))
graph save Graph "$newdir2\figA6.gph", replace


***mentioned in article
//alternative Fig 3

gen discedu=edu-thinkedu
label var discedu "Difference CDF expend and how respondent think was spent on edu"
gen discadmin=admin-thinkadmincdf
label var discadmin "Difference CDF expend and how respondent think was spent on admin"
gen dischealth=health-thinkhealth
label var dischealth "Difference CDF expend and how respondent think was spent on health"
gen discwater=water-thinkwater
label var discwater "Difference CDF expend and how respondent think was spent on water"
gen discroads=roads-thinkroadbridge
label var discroads "Difference CDF expend and how respondent think was spent on roads"
gen discelec=electrification-thinkelectri
label var discelec "Difference CDF expend and how respondent think was spent on electricity"
gen discother=other-thinkoth
label var discother "Difference CDF expend and how respondent think was spent on other"


reg disagreespend i.treatment i.reelected##i.treatment discedu dischealth discwater discroads discelec discadmin  discother thinkmpcorrupt  , vce(cl constituencynow)
estimates store exper1

coefplot exper1, xline(0, lcolor(red) lwidth(thin) lpattern(dash)) omitted baselevels drop(_cons 0.reelected#0.treatment 0.reelected#1.treatment 0.reelected#2.treatment 0.reelected#3.treatment 0.reelected#4.treatment)  levels(95)   xsize(7) ysize(4) ///
     headings(0.treatment = "{bf:Treatment}"                        ///
	          1.reelected = "{bf:MP election status in 2013}"       ///
              0.reelected#0.treatment = "{bf:Interaction Effect}"   ///
			  discedu = "{bf:CDF minus how believed was spent in:}")  saving(second, replace)    
graph save Graph "$newdir2\altfig3panela.gph", replace




reg disagreespend i.treatment i.reelected##i.treatment discedu  dischealth discwater discroads discelec discadmin discother  thinkmpcorrupt   $controls, vce(cl constituencynow)
estimates store exper1

coefplot exper1, scale(*.8 ) xline(0, lcolor(red) lwidth(thin) lpattern(dash)) omitted baselevels drop(_cons 0.reelected#0.treatment 0.reelected#1.treatment 0.reelected#2.treatment 0.reelected#3.treatment 0.reelected#4.treatment)  levels(95)   xsize(10) ysize(7) ///
     headings(0.treatment = "{bf:Treatment}"                        ///
	          0.reelected = "{bf:MP election status in 2013}"       ///
              1.reelected#0.treatment = "{bf:Interaction Effect}"   ///
			  discedu = "{bf:CDF minus how believed was spent in:}"  ///
			  blockluo = "{bf:Controls:}")  saving(firstc, replace)
graph save Graph "$newdir2\altfig3panelb.gph", replace			  









//alternative Fig 4
reg voteagain i.treatment i.reelected##i.treatment  discedu dischealth discwater discroads discelec discadmin discother thinkmpcorrupt, vce(cl constituencynow)
estimates store again
coefplot again, xline(0, lcolor(red) lwidth(thin) lpattern(dash)) omitted baselevels drop(_cons 0.reelected#0.treatment 0.reelected#1.treatment 0.reelected#2.treatment 0.reelected#3.treatment 0.reelected#4.treatment)  levels(95)   xsize(8) ysize(4) ///
     headings(0.treatment = "{bf:Treatment}"                        ///
	          0.reelected = "{bf:MP election status in 2013}"       ///
              1.reelected#0.treatment = "{bf:Interaction Effect}"   ///
			  discedu = "{bf:CDF minus how believed was spent in:}") saving(firstt, replace) 
graph save Graph "$newdir2\altfig4panela.gph", replace


reg voteagain i.treatment i.reelected##i.treatment  discedu dischealth discwater discroads discelec discadmin  discother thinkmpcorrupt $controls , vce(cl constituencynow)
estimates store again
coefplot again, scale(*.8) xline(0, lcolor(red) lwidth(thin) lpattern(dash)) omitted baselevels drop(_cons 0.reelected#0.treatment 0.reelected#1.treatment 0.reelected#2.treatment 0.reelected#3.treatment 0.reelected#4.treatment)  levels(95)   xsize(10) ysize(7) ///
     headings(0.treatment = "{bf:Treatment}"                        ///
	          0.reelected = "{bf:MP election status in 2013}"       ///
              1.reelected#0.treatment = "{bf:Interaction Effect}"   ///
			  discedu = "{bf:CDF minus how believed was spent in:}" ///
			  blockluo = "{bf:Controls:}")  saving(firstc, replace)  
			 
graph save Graph "$newdir2\altfig4panelb.gph", replace




